<?php
namespace app\api\controller;

use app\api\controller;
use think\Validate;
use think\Db;

class Lock extends Base
{   
     
    public function check_lock(){
        $validate = new Validate(['board_number' => 'require',
                                  'lock_number'  => 'require'
                                 ]);
        $validate->message([ 'board_number.require' => '缺少主板编号!',
                             'lock_number.require'  => '缺少锁编号！'
                           ]);

        $data = $this->request->param();

        if (!$validate->check($data)) {
            $this->error($validate->getError());
        }
        
        $Lock = model('Lock');

        if($order_info['cue_info'] = $Lock->checkLockISUse($data['board_number'],$data['lock_number'])){
            //获取该用户的最大红包金额
            $order_info['max_redpacket_info'] = model('redpacket')->getMaxRedpacket($this->userId);
            //获取当前的押金
            $request   = Db::name('system_config')->where('id',1)->find();
            
            //判断用户是否需要缴纳押金
            $order_info['deposit'] = Db::name('user')->where('id',$this->userId)->value('deposit') ? 0 : $request['deposit'];

            
            $order_info['amount']  = $request['amount'];
            $order_info['payment'] = sprintf("%.2f",$order_info['deposit']+$order_info['amount']-$order_info['max_redpacket_info']['max_redpacket_price']);

            $this->success("可以使用",$order_info);
        }
        
        $this->error('请选择使用其它球杆！');



    }

    //验证该锁的
}
